import request from '@/utils/request'

// 查询新风设备列表
export function getFreshAirDeviceList(query) {
  return request({
    url: '/freshair/device/list',
    method: 'get',
    params: query
  })
}

// 查询新风设备详细
export function getFreshAirDevice(deviceId) {
  return request({
    url: '/freshair/device/' + deviceId,
    method: 'get'
  })
}

// 新增新风设备
export function addFreshAirDevice(data) {
  return request({
    url: '/freshair/device',
    method: 'post',
    data: data
  })
}

// 修改新风设备
export function updateFreshAirDevice(data) {
  return request({
    url: '/freshair/device',
    method: 'put',
    data: data
  })
}

// 删除新风设备
export function delFreshAirDevice(deviceId) {
  return request({
    url: '/freshair/device/' + deviceId,
    method: 'delete'
  })
}

// 获取新风设备运行日志
export function getFreshAirDeviceLogs(query) {
  return request({
    url: '/freshair/device/logs',
    method: 'get',
    params: query
  })
}

// 清空新风设备运行日志
export function clearFreshAirDeviceLogs() {
  return request({
    url: '/freshair/device/logs/clear',
    method: 'delete'
  })
}

// 获取新风设备实时数据
export function getFreshAirDeviceData(deviceId) {
  return request({
    url: '/freshair/device/data/' + deviceId,
    method: 'get'
  })
}

// 获取新风设备状态
export function getFreshAirDeviceStatus(deviceId) {
  return request({
    url: '/freshair/device/status/' + deviceId,
    method: 'get'
  })
}

// 控制新风设备
export function controlFreshAirDevice(data) {
  return request({
    url: '/freshair/device/control',
    method: 'post',
    data: data
  })
}

// 获取新风设备参数配置
export function getFreshAirDeviceParams(deviceId) {
  return request({
    url: '/freshair/device/params/' + deviceId,
    method: 'get'
  })
}

// 更新新风设备参数配置
export function updateFreshAirDeviceParams(data) {
  return request({
    url: '/freshair/device/params',
    method: 'put',
    data: data
  })
}

// 获取新风设备温湿度图表数据
// 调整为 POST，请求体传递入参以便与设备联动
export function getFreshAirChartData(data) {
  return request({
    url: '/freshair/device/detail/chart',
    method: 'post',
    data: data
  })
}

// 获取新风设备运行日志
// 调整为 POST，请求体传递入参以便与设备联动
export function getFreshAirTransmitterLogs(data) {
  return request({
    url: '/freshair/transmitter/logs',
    method: 'post',
    data: data
  })
}

// 获取新风设备管理数据
export function getFreshAirDeviceManage(query) {
  return request({
    url: '/freshair/device/manage',
    method: 'get',
    params: query
  })
}

// 设置新风设备工作模式
export function setFreshAirWorkMode(data) {
  return request({
    url: '/freshair/device/workMode',
    method: 'post',
    data: data
  })
}

// 设置新风设备风速等级
export function setFreshAirFanLevel(data) {
  return request({
    url: '/freshair/device/fanLevel',
    method: 'post',
    data: data
  })
}

// 导出新风设备数据
export function exportFreshAirData(query) {
  return request({
    url: '/freshair/device/export',
    method: 'get',
    params: query
  })
}

// 更新新风设备管理参数（编辑详情保存）
// 后端接口：PUT /firewaring/device/manage/{id}
// id 为当前选中设备的 id，data 为 FreshAirDeviceDTO 结构
export function updateFreshAirDeviceManage(id, data) {
  return request({
    url: `/firewaring/device/manage/${id}`,
    method: 'put',
    data: data
  })
}